const Joi = require('@hapi/joi')

module.exports={
  useMiddleware(app){
    app.use((err, req, res, next) => {
      //数据合法性验证失败
      if (err instanceof Joi.ValidationError) {
        return res.ms(err)
      }
    
      //token验证失败
      if (err.name == 'UnauthorizedError') {
        return res.ms('身份验证失败')
      }
    
      console.log(err)
      return res.ms('未知错误')
    })
  }
}